
#include "semantics_class.h"
#include "generic_table.cpp"
#include "main_container.h"
#include "semantic_analyzer.h"
extern MainContainer * CompilerData;

SemanticsClass::SemanticsClass()
{
	this->Name = new GenericTable<int>();
	this->InheritName = new GenericTable<int>();
	
	this->CurrentContext = -1;
	
	this->Classes = new GenericTable<SemanticsClass>();
	this->Fields = new GenericTable<SemanticsField>();
	this->Enums = new GenericTable<SemanticsEnum>();
	this->Properties = new GenericTable<SemanticsProperty>();
	this->Methods = new GenericTable<SemanticsMethod>();
	this->TemplateNames = new GenericTable<int>();

	this->ModifierAbstract = false;
	this->ModifierFinal = false;
	this->ModifierPrivate = false;
	this->ModifierProtected = false;
	this->ModifierPublic = false;
	this->HasTemplate = false;
}


SemanticsClass::~SemanticsClass()
{
	if(Name != NULL)
	{
		delete Name;
		Name = NULL;
	}

	if(InheritName != NULL)
	{
		delete InheritName;
		InheritName = NULL;
	}

	if(Classes != NULL)
	{
		delete Classes;
		Classes = NULL;
	}

	if(Fields != NULL)
	{
		delete Fields;
		Fields = NULL;
	}

	if(Enums != NULL)
	{
		delete Enums;
		Enums = NULL;
	}

	if(Properties != NULL)
	{
		delete Properties;
		Properties = NULL;
	}

	if(Methods != NULL)
	{
		delete Methods;
		Methods = NULL;
	}

	if(TemplateNames != NULL)
	{
		delete TemplateNames;
		TemplateNames = NULL;
	}
}


#ifdef DEBUG
void SemanticsClass::DebugXMLOutput(FILE * fo)
{
	fprintf(fo, "<semanticsClass name=\"");
	SemanticAnalyzer::DebugOutputNameFromTable(fo, this->Name, CompilerData->Units);

	fprintf(fo, "\" inheritName=\"");
	SemanticAnalyzer::DebugOutputNameFromTable(fo, this->InheritName, CompilerData->Units);

	fprintf(fo, "\" currentContext=\"");
	fprintf(fo, "%d", this->CurrentContext);

	fprintf(fo, "\" hasTemplate=\"");
	if (this->HasTemplate)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

	fprintf(fo, "\" templateNames=\"");
	SemanticAnalyzer::DebugOutputNameFromTable(fo, this->TemplateNames, CompilerData->Units);

	fprintf(fo, "\" modifierPrivate=\"");
	if (this->ModifierPrivate)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

	fprintf(fo, "\" modifierPublic=\"");
	if (this->ModifierPublic)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

		fprintf(fo, "\" modifierProtected=\"");
	if (this->ModifierProtected)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

		fprintf(fo, "\" modifierAbstract=\"");
	if (this->ModifierAbstract)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

			fprintf(fo, "\" modifierFinal=\"");
	if (this->ModifierFinal)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

	// tag
	fprintf(fo, "\" >\n");


	// make output of table Classes
	fprintf(fo, "<classes>\n");
	for(int i = 0; i < this->Classes->GetCount(); i++)
	{
		SemanticsClass * data = this->Classes->GetData(i);
		data->DebugXMLOutput(fo);
	}
	fprintf(fo, "</classes>\n");

	// make output of table Fields
	fprintf(fo, "<fields>\n");
	for(int i = 0; i < this->Fields->GetCount(); i++)
	{
		SemanticsField * data = this->Fields->GetData(i);
		data->DebugXMLOutput(fo);
	}
	fprintf(fo, "</fields>\n");

	// make output of table Properties
	fprintf(fo, "<properties>\n");
	for(int i = 0; i < this->Properties->GetCount(); i++)
	{
		SemanticsProperty * data = this->Properties->GetData(i);
		data->DebugXMLOutput(fo);
	}
	fprintf(fo, "</properties>\n");

		// make output of table Enums
	fprintf(fo, "<enums>\n");
	for(int i = 0; i < this->Enums->GetCount(); i++)
	{
		SemanticsEnum * data = this->Enums->GetData(i);
		data->DebugXMLOutput(fo);
	}
	fprintf(fo, "</enums>\n");

		// make output of table Properties
	fprintf(fo, "<methods>\n");
	for(int i = 0; i < this->Methods->GetCount(); i++)
	{
		SemanticsMethod * data = this->Methods->GetData(i);
		data->DebugXMLOutput(fo);
	}
	fprintf(fo, "</methods>\n");

	fprintf(fo, "</semanticsClass>\n");
}
#endif